const { defineConfig } = require('@vue/cli-service')

const PORT = 8080;
const HOST = '127.0.0.1'
const PUBLIC_PATH = './';
const TITLE = '基于PTZ摄像头实验室平台'

const path = require('path');
const resolve = dir => path.join(__dirname, dir); // 路径对接
const ICON_PACKAGE_PATH = './src/assets/icons/svg';

module.exports = defineConfig({
  lintOnSave: false,
  publicPath: PUBLIC_PATH,
  transpileDependencies: true,
  devServer: {
    port: PORT,
    // host: HOST,
    proxy: {
      "/ISAPI": {
        target: "http://127.0.0.1/ISAPI", // 本地nginx服务
        changeOrigin: true,
        ws: true,
        pathRewrite: {
          "^/ISAPI": "/",
        },
      },
      "/SDK": {
        target: "http://127.0.0.1/SDK", // 本地nginx服务
        changeOrigin: true,
        ws: true,
        pathRewrite: {
          "^/SDK": "/",
        },
      },
    }
    // webSocketVideoCtrlProxy反向配置暂未配置成功，当前配置在开发过程不需要打包就可实现除播放视频外的其他功能
  },
  configureWebpack: {
    name: TITLE
  },
  chainWebpack(config) {
    // 修改当前项目默认svg配置,添加svg规则
    config.module.rule('svg')
      .exclude.add(resolve(ICON_PACKAGE_PATH)).end();

    // 设置webpack的svg loader加载svg文件
    config.module.rule('icons')
      .test(/\.svg$/)
      .include.add(resolve(ICON_PACKAGE_PATH)).end()
      .use('svg-sprite-loader')
      .loader('svg-sprite-loader')
      .options({ symbolId: 'icon-[name]' }).end();
  }
})
